<template>
  <a-modal :maskClosable="false"
    :title='title'
    :width='1024'
    :visible='visible'
    :confirmLoading='confirmLoading'
    @ok='handleOk'
    @cancel='handleCancel'
    cancelText='关闭'
    wrapClassName='ant-modal-cust-warp'
    style='top:5%;height: 85%;overflow-y: hidden'>
    <a-card :bordered='false' class='card-area'>

      <!-- 查询区域 -->
      <div class='table-page-search-wrapper'>
        <!-- 搜索区域 -->
        <a-form layout='inline' @keyup.enter.native='searchQuery'>
          <a-row :gutter='12' v-if='queryParam.flag=="1"'>
            <a-col :md="6" :sm="6">
              <a-form-item label="楼栋">
                <a-select v-model='queryParam.bId' style='width: 120px' @change='handleProvince1Change'>
                  <a-select-option value=''>---请选择---</a-select-option>
                  <a-select-option v-for='item in bOption' :key='item.key' :value='item.key'>{{ item.label }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>

            <a-col :md="6" :sm="6">
              <a-form-item label="楼层">
                <a-select v-model='queryParam.lId' style='width: 120px' @change='handleProvince2Change'>
                  <a-select-option value=''>---请选择---</a-select-option>
                  <a-select-option v-for='item in lOption' :key='item.key' :value='item.key'>{{ item.label }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>

            <a-col :md="6" :sm="6">
              <a-form-item label="房间">
                <a-select v-model='queryParam.roomId' style='width: 120px'>
                  <a-select-option value=''>---请选择---</a-select-option>
                  <a-select-option v-for='item in rOption' :key='item.key' :value='item.key'>{{ item.label }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
           <a-col :md="8" :sm="24">
               <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
           </a-col>
        </span>
          </a-row>

        </a-form>
      </div>

      <a-row>
      <a-table
        ref='table'
        size='middle'
        bordered
        rowKey='id'
        :dataSource='dataSource'
        :pagination='ipagination'
        :loading='loading'
        :customRow='doubleClick'
        :rowSelection='{type:selectedType, selectedRowKeys: selectedRowKeys, onChange: onSelectChange }'>
        <a-table-column title='姓名' align='center' dataIndex='realName'></a-table-column>
        <a-table-column title='性别' align='center' dataIndex='sex_dictText'></a-table-column>
        <a-table-column title='年龄' align='center' dataIndex='age'></a-table-column>
        <a-table-column title='床位' align='center' dataIndex='bedInfo' v-if="queryParam.flag=='1'"></a-table-column>
        -->
        <!--        <a-table-column title='客户阶段' align='center'  v-if="queryParam.flag=='0'">未入住</a-table-column>-->
      </a-table>
      </a-row>
    </a-card>
  </a-modal>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction } from '@api/manage'
import { filterObj } from '@/utils/util'

export default {
  name: 'DepartList',
  mixins: [JeecgListMixin],
  data() {
    return {
      description: '住院一览',
      visible: false,
      title: '请选择长者信息',
      confirmLoading: false,
      /* table选择类型，单选radio或多选checkbox  */
      selectedType: 'radio',
      selectedRowKeys: [],
      // 查询条件
      queryParam: {
        //0 未入住，1入住
        flag: '0',
        bId: '',
        lId: '',
        roomId: ''
      },
      columns: [],
      flag: false,
      url: {
        list: '/his/patient/list'
      },
      loading: false,
      disableMixinCreated: true,
      bOption: [],
      lOption: [],
      rOption: []
    }

  },
  computed: {},
  created() {
    const that = this
    getAction('/his/building/tree/selectList', { pid: 0 }).then((res) => {
      that.bOption = res.result
    })
  },
  methods: {
    doubleClick(record, index) {
      var that = this
      return {
        on: {
          // 这里是双击，单击改成click即可
          dblclick: () => {
            if (that.selectedType == 'radio') {
              that.selectedRowKeys = []
              that.$emit('signOk', record)
              that.close()
            }
          }
        }
      }
    },
    show(flag) {
      this.queryParam.flag = flag
      this.queryParam.source = flag==0?1:0;
      this.queryParam.bId="";
      this.queryParam.lId="";
      this.queryParam.roomId="";
      this.visible = true
      this.loadData()
    },
    handleOk() {
      const that = this
      that.selectedRowKeys = []
      if (that.selectedType == 'radio') {
        that.$emit('signOk', this.selectionRows[0])
      } else {
        that.$emit('signOk', this.selectionRows)
      }
      that.close()
    },
    handleCancel() {
      this.close()
    },
    close() {
      this.visible = false
    },
    handleProvince1Change(value) {
      const that = this
      getAction('/his/building/tree/selectList', { pid: value }).then((res) => {
        that.lOption = res.result
      })
    },
    handleProvince2Change(value) {
      const that = this
      getAction('/his/building/tree/selectList', { pid: value }).then((res) => {
        that.rOption = res.result
      })
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less'
</style>